// pages/child1/child1.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select:"",
    status:"",
    list:[{
      ifchoosed:false,
      title:"以下说法正确的是?",
      option:["没长牙的孩子不用“刷”","牙齿掉光了不用刷牙","孩子别用成人牙膏","只用在早上刷牙"],
      answer:"A",
    },
    {
      ifchoosed:false,
      title:"3+1=?",
      option:["3","5","7","4"],
      answer:"D",
    },{
      ifchoosed:false,
      title:"5+1=?",
      option:["2","6","8","4"],
      answer:"B",
    },{
      ifchoosed:false,
      title:"7+1=?",
      option:["2","6","8","4"],
      answer:"C",
    },{
      ifchoosed:false,
      title:"4+4=?",
      option:["2","6","8","4"],
      answer:"C",
    },],
    answerNow:0,
    optionList:["A","B","C","D"],
    successNum:0

  },
  lefttrun:function(){
    if(this.data.answerNow>0){
      this.setData({
        answerNow:this.data.answerNow-1,
        select:'',
        status:''
      })
    }

  },
  righttrun:function(){
    if(this.data.answerNow<this.data.list.length-1){
      this.setData({
        answerNow:this.data.answerNow+1,
        select:'',
        status:''
      })
    }
  },
  selectAnswer:function(e){
    const {item} = e.currentTarget.dataset
    const answer=
    this.data.list[this.data.answerNow].answer
    if(this.data.list[this.data.answerNow].ifchoosed==true){
      console.log("请不要重复选择")
    }
    if(item===answer){
      if(!this.data.list[this.data.answerNow].ifchoosed)
      {
        this.setData({
          successNum:this.data.successNum+1
        })
      }
      console.log("正确")
      this.setData({
        select:item,
        status:"success",
      })
    }else{
      this.setData({
        select:item,
        status:"fail",
       
      })
    }
    if(this.data.answerNow>= this.data.list.length-1)
    {
      app.globalData.userList[0].userAQ+=
      this.data.successNum
      wx.showModal({
        title: '完成答题',  
        content:"请进入排行版查询排名",
        success:function(){
          var list=app.globalData.userList
          const {avatarUrl,nickName} =wx.getStorageSync('userInfo')
          const openid=wx.getStorageSync('openid')
        }
      })
      console.log("完成")
      if(this.data.successNum!=0)
      {
        console.log(this.data.successNum)
      }
      this.setData({
        successNum:0
      })
    }
  },
  turntoChild:function(){
    wx.redirectTo({
      url: "/pages/child/child",
    })
  },
  turntoChild1:function(){
    wx.redirectTo({
      url: "/pages/child1/child1",
    })
  },
  turntoChild2:function(){
    wx.redirectTo({
      url: "/pages/child2/child2",
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})